<template>
  <el-dialog
    :model-value="visible"
    title="支付确认"
    width="420px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    center
    class="payment-dialog"
    @close="handleClose"
    @update:model-value="(val) => $emit('update:visible', val)"
  >
    <div class="payment-content">
      <!-- 支付金额 -->
      <div class="payment-amount">
        <div class="amount-label">支付金额</div>
        <div class="amount-value">¥{{ orderInfo.paymentAmount?.toFixed(2) }}</div>
      </div>
      
      <!-- 订单信息 -->
      <div class="order-info">
        <div class="info-item">
          <span class="label">订单号：</span>
          <span class="value">{{ orderInfo.orderNo }}</span>
        </div>
        <div class="info-item">
          <span class="label">商家：</span>
          <span class="value">{{ storeName }}</span>
        </div>
        <div class="info-item">
          <span class="label">配送地址：</span>
          <span class="value">{{ typeof addressInfo === 'string' ? addressInfo : addressInfo?.address }}</span>
        </div>
      </div>
      
      <!-- 支付方式 -->
      <div class="payment-method">
        <div class="method-title">支付方式</div>
        <div class="method-item selected">
          <div class="method-icon">
            <svg viewBox="0 0 1024 1024" width="24" height="24">
              <path d="M694.355 305.777c-5.99 6.144-9.242 13.926-9.242 22.118 0 8.294 3.251 16.077 9.242 22.118l67.482 67.482H279.552c-17.306 0-31.284 14.08-31.284 31.386s13.978 31.386 31.284 31.386h482.285l-67.482 67.482c-12.186 12.186-12.186 31.949 0 44.237 6.093 6.093 14.08 9.139 22.118 9.139s16.026-3.046 22.118-9.139l121.19-121.19c12.186-12.186 12.186-31.949 0-44.237L738.59 261.54c-12.186-12.186-31.949-12.186-44.235 0z" fill="#1aad19"/>
            </svg>
          </div>
          <span>微信支付</span>
          <el-icon class="check-icon" color="#1aad19"><Check /></el-icon>
        </div>
      </div>
    </div>
    
    <template #footer>
      <div class="payment-actions">
        <el-button @click="handleCancel" :disabled="paying" plain>
          取消订单
        </el-button>
        <el-button 
          type="primary" 
          @click="handlePay"
          :loading="paying"
        >
          {{ paying ? '支付中...' : '立即支付' }}
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { Check } from '@element-plus/icons-vue';

// Props
interface Props {
  visible: boolean;
  orderInfo: any;
  storeName?: string;
  addressInfo?: string | { latitude?: number; longitude?: number; address?: string };
  paying?: boolean;
}

const props = withDefaults(defineProps<Props>(), {
  visible: false,
  orderInfo: () => ({}),
  storeName: '',
  addressInfo: () => ({ address: '' }),
  paying: false
});

// Emits
interface Emits {
  (e: 'update:visible', value: boolean): void;
  (e: 'pay'): void;
  (e: 'cancel'): void;
  (e: 'close'): void;
}

const emit = defineEmits<Emits>();

// 处理支付
const handlePay = () => {
  emit('pay');
};

// 处理取消
const handleCancel = () => {
  emit('cancel');
};

// 处理关闭
const handleClose = () => {
  emit('close');
  emit('update:visible', false);
};
</script>

<style scoped>
/* 支付弹窗样式 */
.payment-dialog .el-dialog__body {
  padding: 30px;
}

.payment-content {
  text-align: center;
}

.payment-amount {
  margin-bottom: 25px;
}

.amount-label {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.amount-value {
  font-size: 36px;
  font-weight: bold;
  color: #ff6600;
}

.order-info {
  margin: 25px 0;
  text-align: left;
  background: #f8f9fa;
  border-radius: 6px;
  padding: 15px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  margin: 8px 0;
  font-size: 14px;
}

.info-item:last-child {
  margin-bottom: 0;
}

.label {
  color: #666;
}

.value {
  color: #333;
  font-weight: 500;
  flex: 1;
  text-align: right;
  word-break: break-all;
}

.payment-method {
  margin: 25px 0;
  text-align: left;
}

.method-title {
  font-size: 14px;
  color: #333;
  margin-bottom: 12px;
}

.method-item {
  display: flex;
  align-items: center;
  padding: 12px 15px;
  border: 2px solid #1aad19;
  border-radius: 8px;
  background: #f0f9f0;
  gap: 10px;
}

.method-icon {
  width: 24px;
  height: 24px;
  color: #1aad19;
}

.check-icon {
  margin-left: auto;
}

.payment-actions {
  display: flex;
  gap: 15px;
  margin-top: 20px;
}

.payment-actions .el-button {
  flex: 1;
  height: 44px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .payment-dialog {
    width: 90% !important;
  }
  
  .payment-actions {
    flex-direction: column;
  }
}
</style>
